﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.ComponentModel;

namespace Milkify.Input
{
    public class GenericKeyGestureValueSerializer : ValueSerializer
    {
        public override bool CanConvertFromString(string value, IValueSerializerContext context)
        {
            return true;
        }

        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            return (value != null);
        }

        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(GenericKeyGesture));
            if (converter != null)
                return converter.ConvertFromInvariantString(value);

            return base.ConvertFromString(value, context);
        }

        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(GenericKeyGesture));
            if (converter != null)
                return converter.ConvertToInvariantString(value);

            return base.ConvertToString(value, context);
        }
    }
}
